import 'package:flutter/material.dart';

/**
 * 自定义文本输入框
 */
class TextFieldItem extends StatefulWidget {
  final Function onChanged;
  final String initialValue;
  final String initialKey;
  final String hint;

  TextFieldItem(
      {Key? key,
      required this.onChanged,
      required this.initialValue,
      required this.initialKey,
      required this.hint})
      : super(key: key);

  @override
  _TextFieldItemState createState() => _TextFieldItemState();
}

class _TextFieldItemState extends State<TextFieldItem> {
  final TextEditingController _controller_key = TextEditingController();

  @override
  void initState() {
    super.initState();
    _controller_key.text = widget.initialValue;
    print("initialValue:${widget.initialValue}");
  }

  @override
  Widget build(BuildContext context) {
    return TextField(
      decoration: InputDecoration(
        labelText: widget.hint,
        hintText: widget.hint,
        border: OutlineInputBorder(),
      ),
      onChanged: (value) {
        setState(() {
          widget.onChanged(widget.initialKey, value);
        });
      },
      controller: _controller_key,
    );
  }
}
